<script setup lang="ts">
import { ref } from 'vue';
import { Search, Monitor } from '@element-plus/icons-vue';

interface Props {
  modelValue: string;
}

interface Emits {
  (e: 'update:modelValue', value: string): void;
  (e: 'hideToTray'): void;
}

defineProps<Props>();
defineEmits<Emits>();

const searchInputRef = ref();

defineExpose({
  searchInputRef,
  focus: () => {
    searchInputRef.value?.focus();
  },
  blur: () => {
    searchInputRef.value?.blur();
  }
});
</script>

<template>
  <div class="top-bar">
    <el-input
      ref="searchInputRef"
      :model-value="modelValue"
      @update:model-value="$emit('update:modelValue', $event)"
      placeholder="搜索应用程序..."
      size="large"
      clearable
      class="search-input"
    >
      <template #prefix>
        <el-icon><Search /></el-icon>
      </template>
    </el-input>
    <el-button 
      type="info" 
      @click="$emit('hideToTray')"
      class="tray-button"
    >
      <el-icon><Monitor /></el-icon>
    </el-button>
  </div>
</template>

<style lang="scss" scoped>
.top-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 30px;
  margin-top: 20px;
  padding: 0 24px;
}

.tray-button {
  flex-shrink: 0;
  border-radius: 50%;
  width: 48px;
  height: 48px;
  padding: 0;
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.3);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(20px) saturate(1.2);
  color: rgba(255, 255, 255, 0.9);
  transition: all 0.3s ease;
  
  &:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
    border-color: rgba(255, 255, 255, 0.4);
  }
  
  &:active {
    transform: translateY(0px) scale(0.95);
  }
  
  .el-icon {
    color: rgba(255, 255, 255, 0.9) !important;
    font-size: 20px;
  }
}

.search-input {
  flex: 1;
}

.search-input :deep(.el-input__wrapper) {
  border-radius: 25px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(20px) saturate(1.2);
  transition: all 0.3s ease;
  
  &:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.4);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
  }
  
  &:focus-within {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.5);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.25), 0 0 0 3px rgba(255, 255, 255, 0.1);
  }
}

.search-input :deep(.el-input__inner) {
  font-size: 16px;
  padding: 12px 20px;
  user-select: none;
  background: transparent;
  color: rgba(255, 255, 255, 0.95);
  
  &::placeholder {
    color: rgba(255, 255, 255, 0.6);
    font-weight: 400;
  }
}

.search-input :deep(.el-input__prefix) {
  color: rgba(255, 255, 255, 0.7);
}

.search-input :deep(.el-input__suffix) {
  color: rgba(255, 255, 255, 0.7);
}
</style>